<?php
function dumpData($data)
// 应用公共文件
{
    echo '<pre>';
    print_r($data);
    die;
}

function imgDomain()
{
    return env('domain.img_url');
}

function logData($data)
{
    \think\facade\Log::warning($data);
}

function transferImgUrl(string $url)
{
    if (!(substr($url, 0, strlen('http')) != 'http')) {
        return $url;
    }
    return env('domain.img_url') . $url;
}

function systemLog($node, $action, $content, $userInfo)
{
    $data = [
        'node' => $node,
        'geoip' => getip(),
        'action' => $action,
        'content' => $content,
        'username' => $userInfo['nickname'],
        'seller_id' => $userInfo['seller_id'],
        'create_at' => time()
    ];
    $table = new \app\model\SystemOplog();
    return $table->insert($data);
}

function getip()
{
    $ip = $_SERVER['REMOTE_ADDR'];
    if (isset($_SERVER['HTTP_CDN_SRC_IP'])) {
        $ip = $_SERVER['HTTP_CDN_SRC_IP'];
    } elseif (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
        foreach ($matches[0] AS $xip) {
            if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
                $ip = $xip;
                break;
            }
        }
    }
    return $ip;
}